package com.maxmlr.music.admin.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import com.maxmlr.music.admin.service.RoleService;
import com.maxmlr.music.admin.entity.Role;
import io.swagger.annotations.*;

import java.io.Serializable;

/**
 * @author max
 * @version 1.0
 * @ClassName AdminRoleController
 * @Description 角色 页面跳转控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@Controller
@Api(value = "/admin/role", tags = "Role 页面跳转控制器")
@RequestMapping("/admin/role")
public class AdmRoleController {

    @Autowired
    public RoleService service;

    /**
     *  功能列表主页
     *
     * @return string
     */
    @GetMapping
    @RequiresPermissions("admin:role:role")
    public String role() {
        return "admin/role/role";
    }

    /**
     *  添加页面
     *
     * @return string
     */
    @GetMapping("/add")
    @RequiresPermissions("admin:role:add")
    public String add(){
        return "admin/role/add";
    }

    /**
     *  编辑页面
     *
     * @return string
     */
    @GetMapping("/edit/{id}")
    @RequiresPermissions("admin:role:edit")
    public String edit(@PathVariable("id") Serializable id , Model model) {
        Role role = service.getById(id);
        model.addAttribute("role", role);
        return "admin/role/edit";
    }


}
